<template>
  <div class="q-pa-md"></div>
</template>

<script>
import {
  softwareloginApi
} from '@/api/user'
import commonUtil from '@/utils/commonUtil'
import { removeToken, setLoginData, setToken } from '@/utils/localStorage'

export default {
  data() {
    return {
      loading: true
    }
  },
  created() {},
  mounted() {
    this.login()
    // 解码用
    //decodeURIComponent(str)
    // 编码用
    //encodeURIComponent(str)
  },
  methods: {
    // 登录
    login() {
      let url = commonUtil.currentURL()
      let data = commonUtil.getURLParameters(decodeURIComponent(url))
      commonUtil.showLoading('正在登录，请稍候')
      softwareloginApi({
        gscode: data.gscode,
        guestcode: data.reguserno,
        operators: data.Operators
      }).then((res) => {
        if (res.code == '0') {
          setToken(res.data.user.token)
          setLoginData(res.data.user)
          setTimeout(() => {
            commonUtil.hideLoading()
            commonUtil.notifySuccess('登录成功')
          }, 1000)
          this.$router.push({
            path: '/'
          })
        } else {
          commonUtil.notifyError('登录失败，请核对账号密码')
        }
      })
    }
  }
}
</script>
